package com.aaa.tars.service.impl;

import com.aaa.tars.dao.RemarkDao;
import com.aaa.tars.entity.Remark;
import com.aaa.tars.entity.Sale;
import com.aaa.tars.service.RemarkService;
import com.aaa.tars.util.CustomException;
import com.aaa.tars.util.Page;
import com.aaa.tars.util.ResultStatus;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @FileName: RemarkServiceImpl
 * @Description:
 * @Author: ghz
 * @CreateTime:2025/9/12 16:47
 * @Version:1.0.0
 */
@Service
public class RemarkServiceImpl implements RemarkService {
    @Resource
    private RemarkDao remarkDao;

    @Override
    public Remark queryById(Integer remarkId) {
        if (remarkId== null|| remarkId<=0){
            throw  new CustomException(ResultStatus.ERROR.getStatusCode(),ResultStatus.ERROR.getStatusMessage());
        }
        return remarkDao.queryById(remarkId);
    }

    @Override
    public PageInfo queryByPage(Page<Remark> page) {
        Integer pageNo = page.getPageNo();
        Integer pageSize = page.getPageSize();
        if (pageNo == null || pageNo <= 0 || pageSize == null || pageSize <= 0){
            throw new CustomException(ResultStatus.ERROR.getStatusCode(),ResultStatus.ERROR.getStatusMessage());
        }
        PageHelper.startPage(pageNo,pageSize);
        Remark remark = page.getData();
        return new PageInfo(remarkDao.queryByParam(remark));
    }

    @Override
    public int insert(Remark remark) {
        remark.setRemarkTime(new Date());
        return remarkDao.insert( remark);
    }

    @Override
    public int update(Remark remark) {
        return remarkDao.update( remark);
    }

    @Override
    public int deleteById(Integer remarkId) {
        if (remarkId== null|| remarkId<=0){
            throw  new CustomException(ResultStatus.ERROR.getStatusCode(),ResultStatus.ERROR.getStatusMessage());
        }
        return remarkDao.deleteById( remarkId);
    }
}
